package com.zmj.sy.mom.srv.aps.controller;


import com.zmj.sy.mom.srv.aps.bean.vo.base.BaseListResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BasePageResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.base.Result;
import com.zmj.sy.mom.srv.aps.bean.vo.dictdata.DictDataFindReqVo;
import com.zmj.sy.mom.srv.aps.bean.vo.workQueue.*;
import com.zmj.sy.mom.srv.aps.service.WorkQueueService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RequiredArgsConstructor
@Api(tags = "工作队列")
@RestController
@RequestMapping("/workQueue")
public class WorkQueueController {
    private final WorkQueueService workQueueService;

    /**
     * @Description: 获取完工率
     *
     * @author: hejiahui
     * @since: 2024/9/19 8:32
     */
    @ApiOperation(value = "1.0 获取完工率", notes = "获取完工率")
    @GetMapping(value = "/workQueueFinishRate")
    public BaseListResVo<WorkQueueGanttChartResVo> workQueueFinishRate(WorkQueueGanttChartReqVo reqVo){
        return workQueueService.workQueueFinishRate(reqVo);
    }

    /**
     * @Description: 获取队列明细
     *
     * @author: hejiahui
     * @since: 2024/9/19 8:32
     */
    @ApiOperation(value = "1.1 获取队列明细", notes = "获取队列明细")
    @GetMapping(value = "/getWorkQueueDetail")
    public BasePageResVo<WorkQueueTaskDetailResVo> getWorkQueueDetail(WorkQueueTaskDetailReqVo reqVo){
        return workQueueService.getWorkQueueDetail(reqVo);
    }
    @ApiOperation(value = "1.1 获取队列明细Post", notes = "获取队列明细")
    @PostMapping(value = "/getWorkQueueDetailPost")
    public BasePageResVo<WorkQueueTaskDetailResVo> getWorkQueueDetailPost(@RequestBody WorkQueueTaskDetailReqVo reqVo){
        if (reqVo.getPlanStartDateTime() != null) {
            reqVo.setPlanStartDateTime(reqVo.getPlanStartDateTime().plusHours(7));
        }
        if (reqVo.getPlanEndDateTime() != null) {
            reqVo.setPlanEndDateTime(reqVo.getPlanEndDateTime().plusHours(7));
        }
        BasePageResVo<WorkQueueTaskDetailResVo> workQueue = workQueueService.getWorkQueueDetail(reqVo);

        for (int i = 0; i < workQueue.getData().size(); i++) {
            WorkQueueTaskDetailResVo node = workQueue.getData().get(i);
            if (node.getWorkTime() != null) {
                node.setWorkTime(node.getWorkTime() / 60);
            }
        }
        return workQueue;
    }
    @ApiOperation(value = "1.2 获取工作区下面的工序", notes = "获取工作区下面的工序")
    @GetMapping(value = "/getWorkPhase")
    public Result<List<WorkPhaseVo>> getWorkPhase(DictDataFindReqVo reqVo){
        return workQueueService.getWorkPhase(reqVo);
    }

}

